package com.iqiyi.dbagent.view.monitor.alarm;

import java.util.HashMap;
import java.util.Map;

import org.slf4j.Logger;
import org.slf4j.LoggerFactory;

import com.iqiyi.dbagent.base.utils.text.JSONUtils;

/**
 * @Title: SelfAlarm.java
 * @Package com.qishu.spark.selfalarm
 * @Description: TODO(无数据接收自动告警)
 * @author wangnianming
 * @date 2015年9月17日 下午3:07:15
 * @version V1.0
 */
public class SelfAlarm {

    private static Logger logger = LoggerFactory.getLogger(SelfAlarm.class);

    /** 对应统一告警平台,卡顿比计算告警主题ID */
    public static final String ARARMTOPICID = "217";

    /** 对应统一告警平台,的项目SECRET KEY */
    public static final String SECRETKEY = "061eb88d-1985-4831-bace-c0555e8a165f";

    /**
     * 传入统一告警平台的告警队列id,已经告警信息,发送告警
     * @param alarm
     * @param secretKey
     */
    public static void sendAlarm(Alarm alarm,String secretKey,String topicId,String alarmInfo) {
        String requestUrl = "http://alert.qiyi.domain/event/create/";
        if (null == secretKey || "".equals(secretKey)){
            secretKey = SECRETKEY;
        }
        if (null == topicId || "".equals(topicId)){
            topicId = ARARMTOPICID;
        }
        logger.info("{},发邮件告知....",alarmInfo);
        try {
            Map<String, String> params = new HashMap<String, String>();
            params.put("secret_key", secretKey);
            params.put("data", JSONUtils.pasre(alarm));
            params.put("topic_id", topicId);
            String resultInfo = HttpRequest.doPost(requestUrl, params, "UTF-8", 20000, 20000);
            logger.info(resultInfo);
        } catch (Exception e) {
            e.printStackTrace();
        }
    }
}
